<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" >

      <el-table-column prop="name" label="区域名称"> </el-table-column>

      <el-table-column prop="type" label="区域类型">
        <template slot-scope="scope">
          <div>
            <span v-if="scope.row.type===1">省</span>
            <span v-else-if="scope.row.type===2">市</span>
            <span v-else>区</span>
          </div>
        </template>
      </el-table-column>

      <el-table-column prop="code" label="区域编码"> </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[10, 20, 30, 50, 100]"
      :page-size="pageInfo.limit"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>   
  </div>
</template>
  
<script>
import axios from 'axios';
export default {
  name: "administrativeRegion",
  componentTitle: "行政区域",
  data() {
    return {
      tableData:[],
      type: [
        {label:"省",value: 1 },
        {label:"市",value: 2 },
        {label:"区",value: 3 },
      ],
       pageInfo:{
         page: 1,
        limit: 20,
        total: 0
       } 
    }
  },
  mounted() {
    this.search();
  },
  methods: {
    search() {
      axios({
        url:'http://192.168.200.251:8888/admin/region/list',
        method:'get',
        params:{
          page: this.pageInfo.page,
          limit: this.pageInfo.limit,
        },
        headers:{
          'Shopping-Admin-Token': sessionStorage.getItem('Shopping-Admin-Token')
        }
      }).then(res=>{
        
        this.pageInfo.total = res.data.data.total

        this.tableData = res.data.data.list;
      })
    },
      handleSizeChange (value) {
      this.pageInfo.limit = value

      this.search()
    },
    // 当前页码的切换
    handleCurrentChange (value) {
      this.pageInfo.page = value

      this.search()
    }
  }
}
</script>
